package com.ruoyi.finance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finance.domain.TSubsidiary;
import com.ruoyi.finance.service.ITSubsidiaryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 辅助核算Controller
 * 
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/subsidiary")
public class TSubsidiaryController extends BaseController
{
    @Autowired
    private ITSubsidiaryService tSubsidiaryService;

    /**
     * 查询辅助核算列表
     */
    @RequiresPermissions("finance:subsidiary:list")
    @GetMapping("/list")
    public TableDataInfo list(TSubsidiary tSubsidiary)
    {
        startPage();
        List<TSubsidiary> list = tSubsidiaryService.selectTSubsidiaryList(tSubsidiary);
        return getDataTable(list);
    }

    /**
     * 导出辅助核算列表
     */
    @RequiresPermissions("finance:subsidiary:export")
    @Log(title = "辅助核算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSubsidiary tSubsidiary)
    {
        List<TSubsidiary> list = tSubsidiaryService.selectTSubsidiaryList(tSubsidiary);
        ExcelUtil<TSubsidiary> util = new ExcelUtil<TSubsidiary>(TSubsidiary.class);
        util.exportExcel(response, list, "辅助核算数据");
    }

    /**
     * 获取辅助核算详细信息
     */
    @RequiresPermissions("finance:subsidiary:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSubsidiaryService.selectTSubsidiaryById(id));
    }

    /**
     * 新增辅助核算
     */
    @RequiresPermissions("finance:subsidiary:add")
    @Log(title = "辅助核算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSubsidiary tSubsidiary)
    {
        return toAjax(tSubsidiaryService.insertTSubsidiary(tSubsidiary));
    }

    /**
     * 修改辅助核算
     */
    @RequiresPermissions("finance:subsidiary:edit")
    @Log(title = "辅助核算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSubsidiary tSubsidiary)
    {
        return toAjax(tSubsidiaryService.updateTSubsidiary(tSubsidiary));
    }

    /**
     * 删除辅助核算
     */
    @RequiresPermissions("finance:subsidiary:remove")
    @Log(title = "辅助核算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSubsidiaryService.deleteTSubsidiaryByIds(ids));
    }
}
